package kroketwebspring.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kroketwebspring.domain.*;
import kroketwebspring.dao.*;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class IndexController extends AbstractController {
	private ProductDAO productDAO;
	
	public void setProductDAO(ProductDAOImpl productDAO) {
		this.productDAO = productDAO;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map m = new HashMap();
		
		HttpSession session = request.getSession(true);
		ArrayList<Product> shoppingCartProducts = productDAO.getProductsArrayList(session);
		
		m.put("shoppingCartProducts", shoppingCartProducts);
		return new ModelAndView("index", m);
	}

}
